package com.yzr.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

/**
 * @description
 * @author: yx-0173
 * @date: 2021-08-24 15:54
 **/
public class ParamServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("用户名 =" + req.getParameter("username"));
        System.out.println("密码 =" + req.getParameter("password"));
        // 如果接收的是多个参数
        System.out.println("兴趣爱好 = " + Arrays.toString(req.getParameterValues("hobby")));
        // System.out.println("兴趣爱好 = " + req.getParameter("hobby"));

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        // 解决POST请求中文乱码
        System.out.println("用户名 =" + req.getParameter("username"));
        System.out.println("密码 =" + req.getParameter("password"));
        // 如果接收的是多个参数
        System.out.println("兴趣爱好 = " + Arrays.toString(req.getParameterValues("hobby")));
    }
}
